import { Toast } from 'vant';
import { Stepper } from 'vant';
export default {
  data() {
    return {
      uniacid1: localStorage.getItem('uniacid'),
      //余额
      member_credit2: 0.0,
      //余额字样
      balanceLang: this.fun.getBalanceLang(),
      income_name_text: "",
      show: false,
      dataInfo: {
        balance_button: [],
        balance_log: []
      }, //保存信息
      name: false,
      Navlis: 'day',
      nameOther: [],
      point_statistics: '',
      uniacid: '',
      isBank: 0,//赢广宝54--限制互转 0可以互转 1不可以互转
      isTixian: 0,//赢广宝54--限制提现 0可以提现 1不可以提现
      duihuanPop: false,//换牛二期-88-兑换积分弹窗
      niuJifen: 699,//换牛二期-88-兑换积分数量
      niuJifenNum: 699,//换牛二期-88-兑换1份积分数量
      isNiuDuiLoadding: false,//换牛二期-88-兑换积分-重复点击
      fenNiuJifen: 1,//换牛二期-88-兑换积分份数
      duihuanFirstPop: false,//换牛二期-88-兑换积分-输入会员id
      duihuanSecondPop: false,//换牛二期-88-兑换积分-确认会员id
      niuUid: '',//换牛二期-88-兑换积分-会员id
    };
  },
  mounted() {
    console.log(this.$route.query.i, 'routerrrrrrrrr', window.location.href);
    this.uniacid = this.$route.query.i;
    if (this.uniacid == '54') {
      this.isCanTixian();
    }

    // localStorage.setItem("uniacid", this.uniacid)
  },
  methods: {
    // 兑换消费积分步进器改变--换牛二期88
    huanniuJifen(e){
      console.log(e,'兑换消费积分步进器改变')
      if(e != ''){
        this.niuJifen = this.niuJifenNum * this.fenNiuJifen
      }
    },
    // 兑换消费积分699--换牛二期88
    duijifen(){
      if(this.isNiuDuiLoadding){
        Toast('请勿重复点击')
        return
      }
      this.isNiuDuiLoadding = true;
      $http.post("HuanNiuJiuji.exchange", { 
          uid: localStorage.getItem("uid"),
          money: this.niuJifen,
          num: this.fenNiuJifen,
          hn_uid: this.niuUid
         }, "加载中").then(response => {
            console.log("HuanNiuJiuji.exchange", response);
            if (response.result == 1) {
              Toast('兑换成功');
              this.duihuanPop = false;
              this.isNiuDuiLoadding = false
              this.niuUid = ''
              this.getBalance();
            }else {
              this.isNiuDuiLoadding = false
            }
      });
    },
    // 兑换积分弹窗换牛二期88
    changeJifen(){
      // this.duihuanFirstPop = true;
      this.duihuanPop = true
    },
    // 兑换积分一次弹窗-取消-换牛二期-88
    cancelDuihuanFirst(){
      this.duihuanFirstPop = false;
      this.duihuanPop = true;
      this.niuUid = ''
    },
    // 兑换积分一次弹窗-确定-换牛二期-88
    confirmDuihuanFirst(){
      if(this.niuUid == ''){
        Toast('换牛会员id不能为空')
        return
      }
      this.duihuanFirstPop = false;
      this.duihuanSecondPop = true;
    },
    // 兑换积分二次弹窗-取消-换牛二期-88
    cancelDuihuanSecond(){
      this.duihuanSecondPop = false;
    },
     // 兑换积分二次弹窗-确定-换牛二期-88
     confirmDuihuanSecond(){
      this.duihuanSecondPop = false;
      this.duihuanPop = true;
    },
    isCanTixian() {
      $http.get("Yingguang.tixianhuzhuan", { uid: localStorage.getItem("uid") }).then(response => {
        console.log("Yingguang.tixianhuzhuan", response);
        if (response.result == 1) {
          this.isBank = response.data.is_bank;
          this.isTixian = response.data.is_tixian;
        }
        console.log(this.isBank, this.isTixian, response.data.is_bank, 'this.isTixian');
      });
    },
    newLoginInformation() { //新登录接口
      $http.get("member.login.new-login-mode").then(response => {
        this.uniacid = response.basic_info.home.item.ViewSet.member.uniacid;
        console.log(response.basic_info.home.item.ViewSet.member.uniacid, '=======');
        if (response.result === 1) {
          let basic_info = JSON.parse(localStorage.getItem("yz_basic_info"));
          this.balance = basic_info.balance;
          this.point = basic_info.point;
          this.country_code = response.data.country_code;//区号
          this.mobile_login_code = response.data.mobile_code_login; //手机验证码登录：0关闭1开启
          this.is_enable = response.data.password_login; //密码登录：0关闭1开启
          this.title.mailInfo_logo = response.data.logo; //商城logo
          this.title.mainHeading = response.data.title1; //主标题
          this.title.subheading = response.data.title2;//副标题
          this.registryEntry = response.data.get_register; //是否显示注册入口
          this.loginToSwitch.mobile_login_code = this.mobile_login_code;
          this.loginToSwitch.is_enable = this.is_enable;
          this.enable_btn = basic_info?.plugin_setting?.account_login?.enable; //账号登录插件开启状态
          this.platformAgreement = response.data.platform_agreement; //平台协议
          this.registrationProtocol = response.data.register_agreement; //注册协议
          this.nameOfTheMall = response.data.shop_name; //商城名称
          this.form.login_checked = response.data.register_agreement?.default_tick == 1 ? true : false; //是否默认勾选
          // #7728 is_year_end_box_login
          // this.is_year_end_box_login = basic_info.plugin_setting.is_year_end_box_login?basic_info.plugin_setting.is_year_end_box_login:false;
          if (this.enable_btn == '1') { //判断是否为账号密码登录
            this.accountAndPasswordLogin = true;
          }
          if (this.enable_btn != '1' && this.is_enable == 1) { //判断是否为手机号密码
            this.phoneAndPassword = true;
          }
          if (this.mobile_login_code && this.is_enable || this.enable_btn == '1') { //登陆方式切换按钮是否显示
            this.loginModeSwitchButton = true;
          }
          if (this.mobile_login_code && this.is_enable || this.enable_btn == '1') { //如果两种登陆都开启了并且手机验证码登陆也开启了就默认显示手机验证码登陆并且显示切换按钮
            if (this.mobile_login_code == 1) {
              this.phoneAndPassword = false;
              this.accountAndPasswordLogin = false;
              this.is_enable = false;
            }
          }
          if (this.appPlatform) { //如果是app端就只显示手机号密码登录并且取消协议默认勾选
            // this.phoneAndPassword = true
            // this.mobile_login_code = 0
            // this.accountAndPasswordLogin = false
            this.form.login_checked = false;
          }
          if (response.data.sms && response.data.sms.captcha.status == "1") {
            this.imgcode = response.data.sms.captcha.img;
          }
          if (this.fun.isWalletApp() && response.data.is_wallet_log) {
            this.isWalletLogin = true;//开启了钱包app登录，只适用于钱包app环境，type为18
            this.requiredInviter = response.validate_page.invite_page;//是否开启邀请码页面，首次钱包登录需要
          }
        } else {
          Toast(response.msg);
        }
      });
    },
    //验证手机身份
    gotoIncome() {
      console.log('验证提现123');
      $http.get("member.member.withdrawByMobile", {}, "loading").then(response => {
        if (response.result === 1) {
          if (response.data.is_bind_mobile == 1) {
            this.$router.push(this.fun.getUrl("withdrawEditmobile", {}));
          } else {
            this.$router.push(this.fun.getUrl("withdrawal", {}));
          }
        } else {
          this.$dialog.alert({ message: response.msg });
        }
      });
    },
    ecological() {
      $http
        .get(
          "plugin.ecological-point.frontend.controllers.page.index",
          { slot_type: this.Navlis },
          "加载中..."
        )
        .then(
          (response) => {
            this.show = true;
            if (response.result == 1) {
              let info_basic = JSON.parse(localStorage.getItem("yz_basic_info"));
              this.balanceLang = info_basic.ecological_point ? info_basic.ecological_point : '生态积分';
              this.fun.setWXTitle(this.balanceLang);
              this.dataInfo = response.data;
              this.point_statistics = response.data.point_statistics;
            } else {
              this.$dialog.alert({ message: response.msg });
            }
          },
          function (response) {
            this.$dialog.alert({ message: response.msg });

          }
        );
    },
    getBalance() {
      var that = this;
      $http
        .get(
          "finance.balance.index",
          {},
          "加载中..."
        )
        .then(
          (response) => {
            this.show = true;
            if (response.result == 1) {
              console.log(this.uniacid, 'finance.balance.index');
              this.dataInfo = response.data;
              if (this.uniacid == '54') {
                let balance_button = response.data.balance_button;
                if (this.isTixian == 1) {
                  let index = balance_button.findIndex(item => item.title === '提现');
                  if (index !== -1) {
                    // 如果找到了对象，使用splice方法删除它
                    balance_button.splice(index, 1);
                    console.log('已删除title为"提现"的对象，其下标为：', index);
                  }
                }
                if (this.isBank == 1) {
                  let index = balance_button.findIndex(item => item.title === '转账');
                  if (index !== -1) {
                    // 如果找到了对象，使用splice方法删除它
                    balance_button.splice(index, 1);
                    console.log('已删除title为"转账"的对象，其下标为：', index);
                  }
                }

              }
              // this.dataInfo = response.data;
              console.log(this.dataInfo.other, this.dataInfo.balance_button);
            } else {
              that.$dialog.alert({ message: response.msg });
            }
          },
          function (response) {
            that.$dialog.alert({ message: response.msg });

          }
        );
    },
    //转化爱心值
    transformingLoveV() {
      this.$router.push(this.fun.getUrl("transformLoveV"));
    },
    // 猫崽积分功能跳转
    transformingTo(key) {
      this.$router.push(this.fun.getUrl("ecologicalPointAward", { status: key }));
    },
    tourlEclogicalPoint(key, json = {}) {
      this.$router.push(this.fun.getUrl(key, json));
    },
    tourl(key, json = {}) {
      console.log(key, json, '提现');
      if (key == 'Balance_recharge') {
        this.$router.push(this.fun.getUrl('balance_recharge'));
        return;
      }
      if (key == 'balance_withdrawals') {
        console.log('1111');
        console.log(this.uniacid, 'that.uniacid');
        if (this.uniacid == '43' || this.uniacid == '46') {

          var that = this;
          $http
            .get(
              "Kanglier.tixian",
              {
                uid: localStorage.getItem("uid")
              },
              "加载中..."
            )
            .then(
              (response) => {
                console.log(response, 'Kanglier.tixian');
                if (response.result == 1) {
                  if (response.data == 1) {
                    this.$router.push(this.fun.getUrl(key, json));
                  } else {
                    that.$dialog.alert({ message: '提现被禁用' });
                  }
                } else {
                  that.$dialog.alert({ message: response.msg });
                }
              },
              function (response) {
                that.$dialog.alert({ message: response.msg });

              }
            );
          return;
        }else if(this.uniacid == '89'){
          var that = this;
          $http
            .get(
              "NiuTwo.get_user_real_name",
              {
                uid: localStorage.getItem("uid")
              },
              "加载中..."
            )
            .then(
              (response) => {
                console.log(response, '是实名认证');
                if (response.result == 1) {
                 if(!response.data.idcard || !response.data.realname){
                  that.$dialog.alert({ message: '暂未实名,请先实名认证' });
                  that.$router.push(this.fun.getUrl('nnRealNameAuth'));
                 }else {
                  that.$router.push(this.fun.getUrl(key, json));
                 }
                } else {
                  that.$dialog.alert({ message: response.msg });
                }
              },
              function (response) {
                that.$dialog.alert({ message: response.msg });

              }
            );
          return;
        }
        this.$router.push(this.fun.getUrl(key, json));


      }

      this.$router.push(this.fun.getUrl(key, json));
    },
    tapNav(key) {
      this.Navlis = key;
      this.ecological();
    },
  },
  activated() {
    if (this.$route.params.name && this.$route.params.name == 'cat') {
      // 如果是猫崽积分
      this.name = this.$route.params.name;
      this.nameOther = [
        {
          img: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FecologicalPoint%2Frangli%402x.png',
          title: '让利奖励',
          id: 1
        },
        {
          img: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FecologicalPoint%2Fjingxiaoshang%402x.png',
          title: '经销商奖励',
          id: 2
        },
        {
          img: 'https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FecologicalPoint%2Fquyu%402x.png',
          title: '区域奖励',
          id: 3
        }
      ];
      this.ecological();
      return;
    }
    this.getBalance();
  }
};